<template>
  <div class="">
    <el-input v-model="input" placeholder="商品名称"></el-input>
    <el-button type="primary" @click="checkout">查询</el-button>
    <el-button type="primary">添加</el-button>
    <el-button type="primary" @click="clearInput">重置</el-button>
    <el-table :data="Goodslist" border style="width: 100%">
      <el-table-column prop="brand_id" label="id" width="180"></el-table-column>
      <el-table-column
        :data="Goodslist"
        prop="name"
        label="商品名称"
        width="180"
      ></el-table-column>
      <el-table-column
        :data="Goodslist"
        prop="retail_price"
        label="售价"
        width="180"
      ></el-table-column>
      <el-table-column
        :data="Goodslist"
        prop="goods_number"
        label="库存"
        width="180"
      ></el-table-column>
      <el-table-column
        :data="Goodslist"
        prop="is_new"
        label="新品"
        width="180"
      ></el-table-column>
      <el-table-column
        :data="Goodslist"
        prop="is_hot"
        label="人气"
        width="180"
      ></el-table-column>
      <el-table-column
        :data="Goodslist"
        prop="is_delete"
        label="上架"
        width="180"
      ></el-table-column>
      <el-table-column
        :data="Goodslist"
        prop="sort_order"
        label="排序"
        width="180"
      ></el-table-column>
      <el-table-column prop=" " label="操作" width="180">
        <el-button type="primary">编辑</el-button>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="pageSize"
      :page-size="10"
      layout="total, sizes, prev, pager, next, jumper"
      :total="count"
    >
    </el-pagination>
  </div>
</template>

 
<script>
import { GoodsApi } from "../../../../../request/api";
export default {
  data() {
    return {
      Goodslist: [],
      is_hot: 1,
      input: "",
      pages: "1",
      size: "10",
      pageSize: [10, 20, 30, 40],
      tableData: [],
      count: 0,
    };
  },
  created() {
    console.log(456);
    GoodsApi({
      page: this.page,
      size: this.size,
    }).then((res) => {
      this.Goodslist = res.data.data;
      this.Goodslist.forEach((x) => {
        x.is_new = x.is_new === 0 ? "否" : "是";
        x.is_hot = x.is_hot === 0 ? "否" : "是";
        x.is_delete = x.is_on_sale === 0 ? "否" : "是";
      });
      let { pageSize, totalPages, data, count } = res.data;

      this.size = pageSize;
      this.totalPages = totalPages;
      this.count = Number(count);

      console.log(this.Goodslist);
    });
  },
  methods: {
    checkout() {
      GoodsApi({
        page: "1",
        name: this.input,
        size: "10",
      }).then((res) => {
        this.Goodslist = res.data.data;
        console.log(this.Goodslist);
      });
    },
    clearInput() {
      this.input = "";
    },
    handleSizeChange(val) {
      this.size = val + "";
      this.initPages();
    },
    // 页码跳转
    handleCurrentChange(val) {
      this.pages = val + "";
      this.initPages();
    },
    initPages() {
      GoodsApi({
        page: this.pages,
        size: this.size,
        name: this.goodsName,
      }).then((res) => {
        let { pageSize, totalPages, data, count } = res.data;
        this.Goodslist = data;
        this.size = pageSize;
        this.totalPages = totalPages;
        this.count = Number(count);
      });
    },
  },
};
</script>
 
<style lang = "less" scoped>
.el-input {
  padding-top: 10px;
  padding-bottom: 10px;
  width: 188px;
  height: 33px;
}
</style>